function push(url) {
  uni.navigateTo({
    url,
  });
}

function replace(url) {
  uni.redirectTo({
    url,
  });
}

function reLaunch(url) {
  uni.reLaunch({ url });
}

function back(delta) {
  if (delta) {
    uni.navigateBack({
      delta,
    });
  } else {
    let pages = getCurrentPages();
    //只有一个页面,返回home
    if (pages?.length == 1) {
      reLaunchHome();
    } else {
      uni.navigateBack();
    }
  }
}

function reLaunchHome() {
  uni.reLaunch({ url: "/views/home/index" });
}

function switchTab(url) {
  uni.switchTab({
    url,
  });
}

export default {
  push,
  replace,
  reLaunch,
  back,
  switchTab,
  reLaunchHome,
};
